package nc.bs.arap.op;

import com.alibaba.fastjson.JSONObject;
import com.yonyou.cloud.utils.StringUtils;

import nc.vo.pub.lang.UFDate;
import nc.vo.pubapp.AppContext;

public class MdmYHSynOp extends AbstractMdmOp{

	@Override
	protected void sendAfter(String result) throws Exception {
		JSONObject root = JSONObject.parseObject(result);
		String code = root.getString("code");
		if("0".equals(code)) {
			getDao().executeUpdate("update bd_bankdoc set def1='Y' where pk_bankdoc in (select tpk from "+temptable+")");
		}
	}

	@Override
	protected String getUrlKey() {
		return "mdm_banklist";
	}

	@Override
	protected String getSql(boolean isqc) {
		
		if(isqc) {
			return "select doc.pk_bankdoc tpk, typ.name as banktype, doc.name as bankname, doc.combinenum as unionnumber, doc.code as bankcode, \r\n" + 
					"'0' as flag\r\n" + 
					"from bd_bankdoc doc \r\n" + 
					"left join bd_banktype typ on typ.pk_banktype=doc.pk_banktype\r\n" + 
					"where doc.combinenum is not null and doc.dr=0 and doc.enablestate = 2 and doc.def1 <> 'Y'\r\n" 
//					+ 
//					"union all\r\n" + 
//					"select doc.pk_bankdoc tpk, typ.name as banktype, doc.name as bankname, doc.combinenum as unionnumber, doc.code as bankcode, \r\n" + 
//					"'1' as flag\r\n" + 
//					"from bd_bankdoc doc \r\n" + 
//					"left join bd_banktype typ on typ.pk_banktype=doc.pk_banktype\r\n" + 
//					"where doc.combinenum is not null and doc.dr=0 and doc.enablestate = 2 and doc.def1 = 'Y'\r\n" + 
//					"union all\r\n" + 
//					"select doc.pk_bankdoc tpk, typ.name as banktype, doc.name as bankname, doc.combinenum as unionnumber, doc.code as bankcode, \r\n" + 
//					"'2' as flag\r\n" + 
//					"from bd_bankdoc doc \r\n" + 
//					"left join bd_banktype typ on typ.pk_banktype=doc.pk_banktype\r\n" + 
//					"where doc.combinenum is not null and (doc.dr=1 or doc.enablestate = 3) and doc.def1 = 'Y'"
					;
		}else {
			UFDate ddate = AppContext.getInstance().getServerTime().getDate();
			
			String date=  ddate.toStdString().substring(0, 10);
			
			return "select doc.pk_bankdoc tpk, typ.name as banktype, doc.name as bankname, doc.combinenum as unionnumber, doc.code as bankcode, \r\n" + 
					"'0' as flag\r\n" + 
					"from bd_bankdoc doc \r\n" + 
					"left join bd_banktype typ on typ.pk_banktype=doc.pk_banktype\r\n" + 
					"where doc.combinenum is not null and doc.dr=0 and doc.enablestate = 2 and doc.def1 <> 'Y' and doc.ts between '"+date+" 00:00:00' and '"+date+" 23:59:59'\r\n" 
//					+ 
//					"union all\r\n" + 
//					"select doc.pk_bankdoc tpk, typ.name as banktype, doc.name as bankname, doc.combinenum as unionnumber, doc.code as bankcode, \r\n" + 
//					"'1' as flag\r\n" + 
//					"from bd_bankdoc doc \r\n" + 
//					"left join bd_banktype typ on typ.pk_banktype=doc.pk_banktype\r\n" + 
//					"where doc.combinenum is not null and doc.dr=0 and doc.enablestate = 2 and doc.def1 = 'Y' and doc.ts between '"+date+" 00:00:00' and '"+date+" 23:59:59'\r\n" + 
//					"union all\r\n" + 
//					"select doc.pk_bankdoc tpk, typ.name as banktype, doc.name as bankname, doc.combinenum as unionnumber, doc.code as bankcode, \r\n" + 
//					"'2' as flag\r\n" + 
//					"from bd_bankdoc doc \r\n" + 
//					"left join bd_banktype typ on typ.pk_banktype=doc.pk_banktype\r\n" + 
//					"where doc.combinenum is not null and (doc.dr=1 or doc.enablestate = 3) and doc.def1 = 'Y' and doc.ts between '"+date+" 00:00:00' and '"+date+" 23:59:59'"
					;
		}
		
	}

}
